package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.FireFighting;
import com.ruoyi.system.mapper.FireFightingMapper;
import com.ruoyi.system.service.FireFightingService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 灭火设施(FireFighting)表服务实现类
 *
 * @author makejava
 * @since 2022-11-16 15:21:40
 */
@Service("fireFightingService")
public class FireFightingServiceImpl implements FireFightingService {
    @Resource
    private FireFightingMapper fireFightingDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FireFighting queryById(Integer id) {
        return this.fireFightingDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param fireFighting 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FireFighting> queryByPage(FireFighting fireFighting, PageRequest pageRequest) {
        long total = this.fireFightingDao.count(fireFighting);
        return new PageImpl<>(this.fireFightingDao.queryAllByLimit(fireFighting, pageRequest), pageRequest, total);
    }

    @Override
    public List<FireFighting> selectList(FireFighting fireFighting) {
        return fireFightingDao.queryAll(fireFighting);
    }

    /**
     * 新增数据
     *
     * @param fireFighting 实例对象
     * @return 实例对象
     */
    @Override
    public FireFighting insert(FireFighting fireFighting) {
        this.fireFightingDao.insert(fireFighting);
        return fireFighting;
    }

    /**
     * 修改数据
     *
     * @param fireFighting 实例对象
     * @return 实例对象
     */
    @Override
    public FireFighting update(FireFighting fireFighting) {
        this.fireFightingDao.update(fireFighting);
        return this.queryById(fireFighting.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.fireFightingDao.deleteById(id) > 0;
    }

    @Override
    public String importExcel(List<FireFighting> fireFightings, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(fireFightings) || fireFightings.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        fireFightingDao.insertBatch(fireFightings);
        return "成功";
    }
}
